\documentclass[aps]{revtex4}
\usepackage{graphicx}
\usepackage{amssymb,amsfonts,amsmath,amsthm}
\usepackage{chemarr}
\usepackage{bm}
\usepackage{pslatex}
\usepackage{mathptmx}
\usepackage{xfrac}

%% concentration notations
\newcommand{\mymat}[1]{\boldsymbol{#1}}
\newcommand{\mytrn}[1]{{#1}^{\mathsf{T}}}
\newcommand{\myvec}[1]{\overrightarrow{#1}}
\newcommand{\mygrad}{\vec{\nabla}}
\newcommand{\myhess}{\mathcal{H}}


\begin{document}
\title{Cubic Splines}
\maketitle

\section{Definition}
Let us assume that we have a signal based on 
$$x_1<\ldots < x_i < \ldots<x_N$$
with values 
$$y_1,\ldots,y_i,\ldots,y_n.$$
The linear interpolation between $x_j$ and $x_{j+1}$ writes
$$
	y = A y_{j} + B y_{j+1}
$$
with
$$
	A = \dfrac{x_{j+1}-x}{x_{j+1}-x_{j}},\;\;
	B = (1-A) = \dfrac{x-x_{j}}{x_{j+1}-x_{j}}.
$$
Let us assume that we know the second derivatives
$$
	y_1'',\ldots,y_i'',\ldots,y_n''.
$$
The we have
$$
	y = A y_{j} + B y_{j+1} + C y_j'' + D y_{j+1}''
$$
with
$$
	C = \dfrac{1}{6}\left(A^3-A\right)\left(x_{j+1}-x_{j}\right)^2,\;\;D=\dfrac{1}{6}\left(B^3-B\right)\left(x_{j+1}-x_{j}\right)^2.
$$
The cubic continuous condition is met when the first derivative is continuous
$$
	y' = \dfrac{y_{j+1}-y_{j}}{x_{j+1}-x_{j}} - \dfrac{3A^2-1}{6}\left(x_{j+1}-x_{j}\right)y_j'' +
	\dfrac{3B^2-1}{6}\left(x_{j+1}-x_{j}\right)y_{j+1}''.
$$
Taking the right and left expression for $1<j<n$ yields
$$
	\dfrac{x_{j}-x_{j-1}}{6} y''_{j-1} + \dfrac{x_{j+1}-x_{j-1}}{3} y''_j + \dfrac{x_{j+1}-x_{j}}{6} y''_{j+1} = 
	\dfrac{y_{j+1}-y_{j}}{x_{j+1}-x_{j}} - \dfrac{y_j-y_{j-1}}{x_j-x_{j-1}}
$$
\section{Natural Spline}
This forces $y_1''=0$ and $y_2''=0$ so that
$$
	\begin{bmatrix}
		1 & 0 & \cdots & \cdots & 0 \\
		\cdots & \cdots & \cdots & \cdots & \cdots \\
		\cdots & \dfrac{x_{j}-x_{j-1}}{6} & \dfrac{x_{j+1}-x_{j-1}}{3} & \dfrac{x_{j+1}-x_{j}}{6} & \cdots\\
		\cdots & \cdots & \cdots & \cdots & \cdots \\
		0 & \cdots & \cdots & 0 & 1 \\
	\end{bmatrix}
	\begin{bmatrix}
	y''_1\\
	\cdots\\
	y''_j\\
	\cdots\\
	y''_n\\
	\end{bmatrix}
	=
	\begin{bmatrix}
	0\\
	\cdots\\
	\dfrac{y_{j+1}-y_{j}}{x_{j+1}-x_{j}} - \dfrac{y_j-y_{j-1}}{x_j-x_{j-1}}\\
	\cdots\\
	0
	\end{bmatrix}
$$

\section{Oriented Spline}
\subsection{Left orientation}
If $y'_1$ is set, then the first two elements of the matrix becomes
$$
	\dfrac{x_2-x_1}{3} \;\text{ and }\; \dfrac{x_2-x_1}{6}
$$
and the first element of the right hand vector becomes
$$
	\dfrac{y_2-y_1}{x_2-x1} - y'_1.
$$
\subsection{Right orientation}
If $y'_n$ is set then the last element of the matrix becomes
$$
	\dfrac{x_n-x_{n-1}}{6}\;\text{ and }\;\dfrac{x_n-x_{n-1}}{3}
$$
and the last element of the right hand vector becomes
$$
	y'_n - \dfrac{y_n-y_{n-1}}{x_n-x_{n-1}}
$$
\subsection{Periodic}
We assume that $y_n=y_1$, then
we must solve a periodic system on $n-1$ points then set $y''_n=y''_1$.
%$$
%	\begin{bmatrix}
%		\dfrac{\left(x_2-x_1\right)+\left(x_n-x_{n-1}\right)}{3} & \dfrac{x_2-x_1}{6} & \cdots &  \dfrac{x_n-x_{n-1}}{6} & 0 \\
%		\cdots & \cdots & \cdots & \cdots & \cdots \\
%		\cdots & \dfrac{x_{j}-x_{j-1}}{6} & \dfrac{x_{j+1}-x_{j-1}}{3} & \dfrac{x_{j+1}-x_{j}}{6} & \cdots\\
%		\cdots & \cdots & \cdots & \cdots & \cdots \\
%		 0 & \dfrac{x_2-x_1}{6} &  & \cdots & \dfrac{x_n-x_{n-1}}{6} & \dfrac{\left(x_2-x_1\right)+\left(x_n-x_{n-1}\right)}{3} \\
%	\end{bmatrix}
%	\begin{bmatrix}
%	y''_1\\
%	\cdots\\
%	y''_j\\
%	\cdots\\
%	y''_n\\
%	\end{bmatrix}
%	=
%	\begin{bmatrix}
%	\dfrac{y_2-y_1}{x_2-x_1}-\dfrac{y_n-y_{n-1}}{x_n-x_{n-1}}\\
%	\cdots\\
%	\dfrac{y_{j+1}-y_{j}}{x_{j+1}-x_{j}} - \dfrac{y_j-y_{j-1}}{x_j-x_{j-1}}\\
%	\cdots\\
%	\dfrac{y_n-y_{n-1}}{x_n-x_{n-1}}-\dfrac{y_2-y_1}{x_2-x_1}\\
%	\end{bmatrix}
%$$


\end{document}